//
//  ABTBController.swift
//  hEhL
//
//  Created by 本 on 16/5/5.
//  Copyright © 2016年 本. All rights reserved.
//

import UIKit

class ABTBController: UITabBarController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        setupNav()
        setupTabBar()
        
    }
    /**
     设置tabbarItem字体大小等等
     */
    override func loadView() {
        super.loadView()
        let TabbarItem = UITabBarItem.appearance()
        var dic = [String : AnyObject]()
        dic[NSFontAttributeName] = UIFont.systemFontOfSize(13)
        
        var dic2 = [String : AnyObject]()
        dic2[NSForegroundColorAttributeName] = UIColor.blackColor()
        dic2[NSForegroundColorAttributeName] = UIColor(red: 1.0, green: 138/255.0, blue: 13/255.0, alpha: 1.0)
        TabbarItem.setTitleTextAttributes(dic, forState: .Normal)
        TabbarItem.setTitleTextAttributes(dic2, forState: .Selected)
    }
    
    func setupTabBar(){

        let tabbar = ABTabbar()
        setValue(tabbar, forKey: "tabBar")
    
    }
    func setupNav(){

        
    
    }
}
extension ABTBController {
    func setupUI(){
        UIImage(named: "icon_more4")!
        UIImage(named: "icon_nav_discovery_selected")!
        let nav = ABHomeNav(rootViewController: ABHomeViewController())
        setupChildController(nav, textTitle: "首页", image:UIImage(named: "icon_nav_tool")! , selectImage: UIImage(named: "icon_nav_tool_selected")!)

        setupChildController(ABSEEVc(), textTitle: "快看", image: UIImage(named: "icon_nav_video")!, selectImage: UIImage(named: "icon_nav_video_selected")!)
        
        setupChildController(ABTrendsVc(), textTitle: "动态", image: UIImage(named: "icon_nav_moment")!, selectImage: UIImage(named: "icon_nav_moment_selected")!)
        setupChildController(ABMeVc(), textTitle: "我的", image: UIImage(named: "icon_nav_my")!, selectImage: UIImage(named: "icon_nav_my_selected")!)
    }

}

// MARK: - 封装添加子控制器

extension ABTBController {
    func  setupChildController(ViewController : UIViewController, textTitle : String, image : UIImage, selectImage : UIImage){

        
        let vc = ViewController
        vc.tabBarItem.title = textTitle
        vc.tabBarItem.image = image
        vc.tabBarItem.selectedImage = selectImage
        addChildViewController(vc)
        
    }
    


}